io.write('YuanJinZhi  n=')
n=io.read()
io.write('YuanJinZhi  Shu x=')
x=io.read()
io.write('XinJinZhi N=')
N=io.read()

print()

if(n==10) then
	io.write('10JinZhiShu : ' .. x)
else
	a=string.len(x)-1
	s=0
	for i=1,string.len(x) do
		s=s+string.sub(x,i,i)*n^a
		a=a-1
	end

	io.write('10JinZhiShu : ' .. s)	
	print()
	print()
end

if(N==10) then
	io.write('10JinZhiShu : ' .. s)
else
	x=s
	b={}
	i=0
	while(true) do
		i=i+1
		b[i]=x%N
		x=(x-x%N)/N
		if(x==0) then
			break
		end
	end

	c={}
	f=1
	for i=string.byte('a'),string.byte('z') do
		c[f]=string.char(i)
		f=f+1
	end

	io.write(N .. 'JinZhiShu : ')
	for j=#b,1,-1 do
		if(b[j]>9) then
			b[j]=c[b[j]-9]
		end
		io.write(b[j])
	end
	print()
end
